#include "gtest/gtest.h"
#include <acapella/queue/queue.h>
#include <acapella/delegate/delegate.hpp>


int testFunc(int i)
{
	return i;
}

TEST(SimpleQueueTest, NormalTest)
{
	acapella::queue::SimpleQueue<int> testQueue;

	testQueue.Send(1);
	testQueue.Send(2);
	testQueue.Send(3);
	testQueue.Send(4);

	int result = 0;

	ASSERT_EQ(0, testQueue.Recv(result));
	ASSERT_EQ(1, result);
	ASSERT_EQ(0, testQueue.Recv(result));
	ASSERT_EQ(2, result);
	ASSERT_EQ(0, testQueue.Recv(result));
	ASSERT_EQ(3, result);
	ASSERT_EQ(0, testQueue.Recv(result));
	ASSERT_EQ(4, result);
}

TEST(SimpleQueueTest, DelegateTest)
{
	typedef acapella::delegate::delegate<int(int)> delegateType;
	typedef acapella::shared_ptr<delegateType> delegateTypePtr;

	acapella::queue::SimpleQueue<acapella::shared_ptr<delegateType> > testQueue;

	delegateTypePtr pDelegate(new delegateType(
		delegateType::functor_type(&testFunc), 1));
	testQueue.Send(pDelegate);

	pDelegate = delegateTypePtr(new delegateType(delegateType::functor_type(&testFunc), 2));
	testQueue.Send(pDelegate);

	pDelegate = delegateTypePtr(new delegateType(delegateType::functor_type(&testFunc), 3));
	testQueue.Send(pDelegate);



	ASSERT_EQ(0, testQueue.Recv(pDelegate));
	ASSERT_EQ(1, pDelegate->Do());
	ASSERT_EQ(0, testQueue.Recv(pDelegate));
	ASSERT_EQ(2, pDelegate->Do());
	ASSERT_EQ(0, testQueue.Recv(pDelegate));
	ASSERT_EQ(3, pDelegate->Do());

}